package com.atguigu.edu.realtime.utils;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 杨晨昱
 */
public class TreadPoolUtil {
    private static volatile ThreadPoolExecutor poolExecutor;

    public static ThreadPoolExecutor getInstance(){
        if (poolExecutor == null) {
            synchronized (TreadPoolUtil.class) {
                if (poolExecutor == null) {
                    System.out.println("~~~创建线程池对象~~~");
                    poolExecutor = new ThreadPoolExecutor(
                            4, 20, 300, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(Integer.MAX_VALUE)
                    );
                }
            }
        }
        return poolExecutor;
    }
}
